package com.woniu.woniuproject.controller.admin;

import com.github.pagehelper.PageInfo;
import com.woniu.woniuproject.entity.LooseLabel;
import com.woniu.woniuproject.service.LooseLabelService;
import com.woniu.woniuproject.utils.ResponseResult;
import com.woniu.woniuproject.vo.Page;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 功能描述:<br>
 * 〈〉
 *
 * @author 徐威
 * @create 2020/11/16
 * @since 1.0.0
 */
@RestController
@RequestMapping("LooseLabe")
public class LooseLabelController {
    @Autowired
    LooseLabelService looseLabelService;

    /**
     * 未审核散标查询 status 状态 0 待审核
     * @param page 分页
     * @param startDate 起始时间
     * @param endDate 终止时间
     * @return
     */
    @GetMapping("/query")
    public ResponseResult<PageInfo<LooseLabel>> queryByDate(Page page, String startDate, String endDate){
        Date startDates = null;
        Date endDates = null;
        try {
            if (startDate!=null&&endDate!=null){
                startDates = new SimpleDateFormat( "yyyy-MM-dd").parse(startDate);
                endDates = new SimpleDateFormat( "yyyy-MM-dd").parse(endDate);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        PageInfo<LooseLabel> looseLabelPageInfo = looseLabelService.queryByAplay(startDates, endDates, page,0);
        return new ResponseResult<>(looseLabelPageInfo);
    }
    /**
     * 未发布散标查询 status 状态 3 待发布
     * @param page 分页
     * @param startDate 起始时间
     * @param endDate 终止时间
     * @return
     */
    @GetMapping("/Unpublished")
    public ResponseResult<PageInfo<LooseLabel>> UnpublishedByDate(Page page, String startDate, String endDate){
        Date startDates = null;
        Date endDates = null;
        try {
            if (startDate!=null&&endDate!=null){
                startDates = new SimpleDateFormat( "yyyy-MM-dd").parse(startDate);
                endDates = new SimpleDateFormat( "yyyy-MM-dd").parse(endDate);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        PageInfo<LooseLabel> looseLabelPageInfo = looseLabelService.queryByAplay(startDates, endDates, page,3);
        return new ResponseResult<>(looseLabelPageInfo);
    }

    /**
     * 修改散标状态
     * @param status 审核成功和失败状态 1成功 2失败 3待发布 4已发布
     * @param labelid 进行审核的散标id
     * @return
     */
    @GetMapping(value = "/modify")
    public ResponseResult<Object> modifyByAplay(int status,int labelid){

        int code = 500;
        String msg ="请重新确认在审核";
       int rew = looseLabelService.madifyStatusByid(status,labelid);
       if (rew>0){
           code = 200;
           msg = "审核成功";
       }
        return  new ResponseResult<>(code,msg);
    }

}
